<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Drawflashchart
{
	public $line;
	public $y_axis;
	public $x_axis;
	public $elements = array();
	
	function Drawflashchart()
	{
		
	}
	
	function line($color,$data,$label=array("tip"=>"","x"=>"","y"=>""),$text="",$width=1,$dotsize=5)
	{
		$this->line = "";
		$this->line->type = "line";
		$this->line->width = "2";
		$this->line->{'dot-size'} = "5";
		$this->line->colour = $color;
        if($text!="")
        {
        	$this->line->text = $text;
        }
		if($label["tip"]!="")
		{
			$values = array();
			foreach ($data as $v)
			{
				$values[] = array(
								"value"=>$v,
								"tip"=>$label["tip"]."<br>"."#x_label#".$label["x"]."<br>"."#val#".$label["y"],
								"dot-size"=>5
								);
			}
			$this->line->values = $values;
		}else
		{
			$this->line->values = $data;
		}
		
		$this->elements[] = $this->line;
		
		
		
	}
	
	function set_x_label($step="",$label,$min="",$max="")
	{
	    $this->x_axis["offset"] = false;
	    $labels["labels"] = array();
	    if($step>0)
		{
			$this->x_axis["steps"] = $step;
			$labels["steps"] = $step;
		}
		if(is_array($label))
		{
			$labels["labels"] = $label;
		}else
		{
			$step = $step>0?$step:1;
			for ($i=$min;$i<=$max;$i++)
			{
				$labels["labels"][] = $i.$label;
			}
				
		}
		$this->x_axis["labels"] = $labels;	
	}
	function set_x($min,$max,$step=0)
	{
		$this->x_axis = array(
							"min"=>$min,
							"max"=>$max
							);
		if($step>0)
		{
			$this->x_axis["steps"] = $step;
		}					
							
	}
	function set_y($min,$max,$step=0)
	{
		$this->y_axis = array(
							"min"=>$min,
							"max"=>$max
					);
		if($step>0)
		{
			$this->y_axis["steps"] = $step;
		}			
	}
	function out_put()
	{
		$result = array(
					"y_axis"=>$this->y_axis,
					"x_axis"=>$this->x_axis,
					"elements"=>$this->elements
		
					);
		
		return json_encode($result);	
	}
	
}


?>